package com.dingli.admin.service.impl;

import com.dingli.admin.service.ISystemService;
import com.dingli.framework.entity.Theme;
import com.dingli.framework.entity.User;
import com.dingli.framework.mapper.ThemeMapper;
import com.dingli.framework.mapper.UserMapper;
import com.dingli.framework.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemService implements ISystemService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private ThemeMapper themeMapper;

    @Override
    public Response<User> login(Long userId, String password) {
        User currentUser = userMapper.login(userId, password);
        return new Response<>(200, "success", currentUser);
    }

    @Override
    public Response<List<Theme>> getThemeList() {
        return new Response<>(200, "success", themeMapper.selectAll());
    }

    @Override
    public Response<Object> setUserTheme(Long userId, Long themeId) {
        int count = userMapper.setUserTheme(userId, themeId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }

    }
}
